//
// * Copyright (c) 2002-2009 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.kernel.impl.util
{

	using ArrayMap = org.neo4j.kernel.impl.util.ArrayMap;

	using Test = junit.framework.Test;
	using TestCase = junit.framework.TestCase;
	using TestSuite = junit.framework.TestSuite;

	public class TestArrayMap : TestCase
	{
		public TestArrayMap(string testName) : base(testName)
		{
		}

		static void Main(string[] args)
		{
			junit.textui.TestRunner.run(suite());
		}

		public static Test suite()
		{
			TestSuite suite = new TestSuite(typeof(TestArrayMap));
			return suite;
		}

		public virtual void setUp()
		{
		}

		public virtual void tearDown()
		{
		}

		public virtual void testArrayMap()
		{
			ArrayMap<string, int> map = new ArrayMap<string, int>();

			assertTrue(map.get("key1") == null);
			map.put("key1", 0);
			assertEquals(new int(0), map.get("key1"));
			assertEquals(new int(0), map.get("key1"));
			map.put("key1", 1);
			assertEquals(new int(1), map.get("key1"));
			map.put("key2", 0);
			assertEquals(new int(0), map.get("key2"));
			map.put("key2", 2);
			assertEquals(new int(2), map.get("key2"));
			assertEquals(new int(2), map.Remove("key2"));
			assertTrue(map.get("key2") == null);
			assertEquals(new int(1), map.get("key1"));
			assertEquals(new int(1), map.Remove("key1"));
			assertTrue(map.get("key1") == null);

			map.put("key1", 1);
			map.put("key2", 2);
			map.put("key3", 3);
			map.put("key4", 4);
			map.put("key5", 5);
			assertEquals(new int(5), map.get("key5"));
			assertEquals(new int(4), map.get("key4"));
			assertEquals(new int(3), map.get("key3"));
			assertEquals(new int(2), map.get("key2"));
			assertEquals(new int(1), map.get("key1"));
			assertEquals(new int(5), map.Remove("key5"));
			assertEquals(new int(1), map.get("key1"));
			assertEquals(new int(4), map.get("key4"));
			assertEquals(new int(3), map.get("key3"));
			assertEquals(new int(2), map.get("key2"));
			assertEquals(new int(3), map.Remove("key3"));
			assertEquals(new int(1), map.Remove("key1"));
			assertEquals(new int(2), map.Remove("key2"));

			for (int i = 0; i < 100; i++)
			{
				map.put("key" + i, i);
			}
			for (int i = 0; i < 100; i++)
			{
				assertEquals(new int(i), map.get("key" + i));
			}
			for (int i = 0; i < 100; i++)
			{
				assertEquals(new int(i), map.Remove("key" + i));
			}
			for (int i = 0; i < 100; i++)
			{
				assertTrue(map.get("key" + i) == null);
			}
		}
	}

}